import UIKit

let superViewColor = #keyPath(UIView.superview.backgroundColor)

let view = UIView(frame: CGRectMake(0, 0, 100, 100))
view.backgroundColor = .green

let label = UILabel(frame: CGRectMake(0, 0, 100, 40))
view.addSubview(label)

//获取label的父视图的背景颜色
label.superview?.backgroundColor
//kvc方式获取
label.value(forKeyPath: superViewColor)
